package org.example.struct.array2;

import com.alibaba.fastjson.JSON;

import java.util.*;

/**
 * @author liyishan
 * @date 2024/7/24 09:45
 * @apiNote
 */

public class Test02766RelocateMarbles {
    public static void main(String[] args) {
        int[] nums = {3,4};
        int[] moveFrom = {4,3,1,2,2,3,2,4,1};
        int[] moveTo =   {3,1,2,2,3,2,4,1,1};
        List<Integer> res = relocateMarbles(nums,moveFrom,moveTo);
        System.out.println(JSON.toJSON(res));
    }

    public static List<Integer> relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) {
        List<Integer> res = new ArrayList<>();
        Map<Integer,Boolean> map = new HashMap<>();
        for(int i = 0;i<nums.length;i++){
            map.put(nums[i],true);
        }
        for(int i =0;i< moveFrom.length;i++){
            map.remove(moveFrom[i]);
            map.put(moveTo[i],true);
        }
        for(Map.Entry<Integer,Boolean> entry:map.entrySet()){
            res.add(entry.getKey());
        }
        Collections.sort(res);
        return res;
    }
}
